<?php
include_once "../negocio/Vehiculo.php";
$Vehiculo = new Vehiculo();
include_once "../negocio/Cliente.php";
$Cliente = new Cliente();
$Cliente->buscarClientes();
$arregloObjetoFinal = $Cliente->getArregloObjetos();
//print_r($arregloObjetoFinal);
if(isset($_REQUEST['button']))
{

    $Vehiculo->setCliente($_REQUEST['cliente']);
    $Vehiculo->setPatente($_REQUEST['patente']);
    $Vehiculo->setTipo($_REQUEST['tipo']);
    $Vehiculo->setMarca($_REQUEST['marca']);
    $Vehiculo->setModelo($_REQUEST['modelo']);
    $Vehiculo->setNmotor($_REQUEST['nmotor']);
    $Vehiculo->setAnyofabric($_REQUEST['anyofabric']);
    $Vehiculo->setNchasis($_REQUEST['nchasis']);
    $Vehiculo->setColor($_REQUEST['color']);
    $Vehiculo->setCombustible($_REQUEST['combustible']);
    $validacion =$Vehiculo->ingresarVehiculo();

}

?>
<html>
    <head>
    <link href="css/estilo_principal.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" language="JavaScript" src="js/jquery.js"></script>
    <script type="text/javascript" language="JavaScript" src="js/jquery.validate.js"></script>
    <script type="text/javascript" language="JavaScript" src="js/messages_es.js" charset="utf-8"></script>


    <script>
        $(document).ready(function(){
        $("#categoria_agregar").validate();
        });

    </script>

    </head>

    <body style="background-color:#F3F3F3">
<?php
if( isset($validacion) && $validacion==1) echo "<div>Vehiculo agregado Correctamente<div>";
else if( isset($validacion) && $validacion==0) echo "<div class=\"error\">Patente ya Existe</div>";
?>
    <h2>Agregar Vehículo Cliente</h2>
<hr>
    <script>
    window.dhx_globalImgPath = "js/imgs/";
    </script>
    <link rel="STYLESHEET" type="text/css" href="js/dhtmlxcombo.css">
    <script  src="js/dhtmlxcommon.js"></script>
    <script  src="js/dhtmlxcombo.js"></script>
      <form method="post" id="categoria_agregar" action="">
      <table width="100%">
        <tr>
            <td>Cliente</td>
              <td>
            <select  id="combo_zone1" name="cliente">
                <option value=""></option>
                <?
                        for($i=0;$i<count($arregloObjetoFinal);$i++)
                            {
                                $obj = $arregloObjetoFinal[$i];
                                ?>
                                <option value="<?=$obj->getRut();?>"><?=$obj->getNombres()." ".$obj->getApellido_p()." ".$obj->getApellido_m()." - ".$obj->getRut();?></option>
                                <?php
                            }
                  ?>
            </select>
              </td>
          </tr>
          <tr>
            <td width="17%">Patente</td>
            <td width="83%">
                <input type="text" class="required" name="patente" id="patente" value=""/>
            </td>
            <td>Tipo Vehículo</td>
            <td width="83%">
                <input type="text" class="required" name="tipo" id="tipo" value=""/>
            </td>
        </tr>
          <tr>
            <td width="17%">Marca</td>
            <td width="83%">
                <input type="text" class="required" name="marca" id="marca" value=""/>
            </td>
            <td>Modelo</td>
            <td width="83%">
                <input type="text" class="required" name="modelo" id="modelo" value=""/>
            </td>
        </tr>
          <tr>
            <td width="17%">Número Motor</td>
            <td width="83%">
                <input type="text" class="required" name="nmotor" id="nmotor" value=""/>
            </td>
            <td>Año Fabricación</td>
            <td width="83%">
                <input type="text" class="required" name="anyofabric" id="anyofabric" value=""/>
            </td>
        </tr>
          <tr>
            <td width="17%">Número Chasis</td>
            <td width="83%">
                <input type="text" class="required" name="nchasis" id="nchasis" value=""/>
            </td>
            <td>Color</td>
            <td width="83%">
                <input type="text" class="required" name="color" id="color" value=""/>
            </td>
        </tr>
        <tr>
            <td width="17%">Combustible</td>
            <td width="83%">
                <input type="text" class="required" name="combustible" id="combustible" value=""/>
            </td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="submit" name="button" id="button" value="Guardar Vehículo" /></td>
        </tr>
      </table>
  </form>
    <script>
        var z = dhtmlXComboFromSelect("combo_zone1");
        z.enableFilteringMode(true);
    </script>
</body>
 </html>